package com.bes.aiProject.config;

import org.springframework.util.CollectionUtils;

import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

public class MyUtils {

    public class MSG {
        public static final String SUCCESS = "异常检测成功！";
        public static final String NO_HISTORY = "历史数据不足！";
        public static final String NO_PREDICT = "无待检测数据！";
        public static final String AI_CALL_ERROR = "调用AI接口报错！";
        public static final String AI_REQUEST_ERROR = "调用AI接口返回错误！";
    }

    public static Map<String, List<String>> ConditionMap = new HashMap<String, List<String>>() {
        {   //映射条件和code /name/score字段的关系，方便取数
            put("地市", new ArrayList<>(Arrays.asList("area_code", "area_name", " ")));
            put("客户", new ArrayList<>(Arrays.asList("customer_type", "customer_name", " ")));
            put("商业过程", new ArrayList<>(Arrays.asList("enterprise_code", "enterprise_name", "enterpriseScore")));
            put("业务", new ArrayList<>(Arrays.asList("business_code", "business_name", "businessScore")));
            put("环节", new ArrayList<>(Arrays.asList("task_code", "task_name", "taskScore")));
        }
    };


    public enum RESULT_STATUS {
        SUCCESS,
        ERROR;
    }

    public enum ANOMALY_RESULT {
        UP,
        NORMAL,
        DOWN;
    }

    public enum JOB {
        ANOMALY_CHECK("anomalyCheck", "异常检测任务"),
        MODEL_TRAIN("modelTrain", "模型训练任务"),
        MODEL_PREDICT("modelPredict", "模型预测任务");

        private String jobId;
        private String JobName;

        JOB(String jobId, String jobName) {
            this.jobId = jobId;
            this.JobName = jobName;
        }

        public String getJobId() {
            return jobId;
        }

        public String getJobName() {
            return JobName;
        }
    }


    public static int uuidForInt() {
        int id = UUID.randomUUID().toString().replace("-", "").hashCode();
        return id > 0 ? id : -id;
    }

    public static String getGroupConditions(List<String> conditions) {
        List<String> groupConditionList = new ArrayList<>();
        for (String condition : conditions) {
            if (CollectionUtils.isEmpty(ConditionMap.get(condition))) continue;
            //添加code和name
            groupConditionList.add(ConditionMap.get(condition).get(0));
            groupConditionList.add(ConditionMap.get(condition).get(1));
        }
        return groupConditionList.stream().collect(Collectors.joining(","));
    }


}
